The present disclosure relates to performance optimizations of computer programs in general, and to compile time data layout optimizations of computer programs in particular.
Performance of a computer program may be improved based on performance optimizations methods. Such methods include modifying the computer program, also referred to as a target program, to perform in a more efficient manner such as for example to be executed more rapidly, to require less resources such as memory space or draw less power. Although referred to as optimizing performance of the target program, such methods do not necessarily provide the best possible performance. In some cases, performing an optimization may unfortunately lead to a reduction in efficiency of the target program in some executions or even unexpectedly in all executions.
Data layout optimizations are utilized to change a structure layout used in the target program so as to better correspond to data access patterns exercised by the target program. Some optimizations utilize affinity between fields of the structure to determine the structure layout in the optimized target program as to improve spacial locality. For example, a c-like structure having four fields: f1, f2, f3, f4 may be utilized by the target program by constantly accessing field f2 before accessing field f4 and by constantly accessing field f1 after accessing field f3. The affinity between fields f1 and f3 and between fields f2 and f4 may be utilized. The optimized target program may define a structure with the fields arranged in a different order, such as for example, f3, f1, f2, f4 . The different data layout may take into account the order of accesses (e.g., field f3 is accessed before field f1) and the group of fields accessed in proximate instructions (e.g., fields f3 and f1 are usually accessed in together or in relatively close instructions) or the like.
Data layout optimizations may be utilized in a compiler, as is known in the art, to optimize the compiled target program. At compile time, the compiler may utilize the affinity between fields to determine a data layout associated with a structure. The data layout may be different than that defined by the target program (e.g., by the code defining the structure). The compiler may modify the target program so that the compiled target program may have the substantially the same effect as though the data layout was as defined, except for improved performance. The improved performance may be achieved due to spacial locality improvement, as is known in the art.